package it.xiuxian.personcenter.presenter


import android.widget.Toast
import com.lzy.okgo.OkGo
import com.lzy.okgo.callback.StringCallback
import com.lzy.okgo.model.Response
import it.xiuxian.lib.base.*

import it.xiuxian.lib.http.CallBackOption
import it.xiuxian.lib.http.HttpConfig
import it.xiuxian.lib.http.SPConfig
import it.xiuxian.lib.utils.AESUtils
import it.xiuxian.lib.utils.SPUtil
import it.xiuxian.personcenter.activity.FaceActivity
import it.xiuxian.personcenter.activity.ShiMingActivity
import it.xiuxian.personcenter.bean.ImageBean
import it.xiuxian.personcenter.fragment.PersonCenterFragment
import org.json.JSONObject
import java.io.File

class FaceActivityPresenter:BasePresenter<FaceActivity>() {
    fun shiming(idcard: String,name: String,idcardzheng:String,idcardfan:String,faceurl:String){
        val json1 = JSONObject()
        json1.put("name",name)
            .put("idcard",idcard)
            .put("idcardzheng",idcardzheng)
            .put("idcardfan",idcardfan)
            .put("faceurl",faceurl)
        val s = AESUtils.encryptAES_ECB(json1.toString())
        OkGo.post<BaseBean<String>>(HttpConfig.BASE_URL+"/appshiming/tijiao")
            .params("encrypt", s)
            .execute(object : CallBackOption<BaseBean<String>>() {}.loadBind(mView as FaceActivity).execute(
                object : ILoadBind<BaseBean<String>> {
                    override fun excute(bean: BaseBean<String>) {
                        if (bean.code==0){
                            (mView as FaceActivity).setData(bean.msg)
                        }
                    }
                }
            ))
    }
    fun onload(file: File){
        OkGo.post<BaseBean<ImageBean>>(HttpConfig.BASE_URL + "/appshiming/uploadImg")
            .isMultipart(false)
            .params("imgurl", file)
            .execute(object : CallBackOption<BaseBean<ImageBean>>() {}.loadBind(mView as FaceActivity).execute(
                object :ILoadBind<BaseBean<ImageBean>>{
                    override fun excute(bean: BaseBean<ImageBean>) {
                        if(bean.code==0){
                            (mView as FaceActivity).updata(bean.data)
                        }
                    }
                }
            ))
    }

}